// packageC/pages/package/OCR_namage/show_img/index.js
const mybehavior = require("../../../../../behaviors/requests")
Page({

  /**
   * 页面的初始数据
   */
  behaviors: [mybehavior],
  data: {
    baseUrl: "https://logisticsengineering.gree.com/ocr_calling_api/gaolan_ocr_bp",
    img_src: "",
    view_class: "statu_class1",
    point_show: false,
    point_index: ""
  },
  preViewImg(e) {
    let lists = []
    lists.push(e.target.dataset.url)

    wx.previewImage({
      current: e.target.dataset.url,
      urls: lists,
    })
  },
  // 查询-库位状态--集合
  searchHouseStatus() {
    wx.showLoading({
      title: '处理中...',
    })
    let row = this.data.row_data
    let url = this.data.baseUrl + "/query_points";
    let data = {
      uid: row.uid,
      page: 1,
      page_size: 1,
    }

    this.post(url, data).then(res => {
      console.log("返回结果", res)
      if (res.code == 20000) {
        wx.hideLoading()
        let val = res.data.results[0]
        this.setData({
          img_src: val.points[this.data.point_index],
          report_time: this.GMTToStr(val.report_time)
        })
        wx.showToast({
          title: res.msg,
          icon: "none"
        })
        let flag = res.data.results[this.data.point_index].als
        if (flag == "A") {
          console.log("空库");
          self.setData({
            ku_status: "空库",
            view_class: "statu_class2",
          })

        } else {
          console.log("满库");
          self.setData({
            ku_status: "满库",
            view_class: "statu_class1",
          })
        }

      } else {

        wx.showToast({
          title: res.msg,
          icon: "error"
        })
      }
    }).catch(err => {
      // this.setData({
      //   data_list: []
      // })
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
      wx.hideLoading()
    })
  },
  // 查询-原始图片--集合
  searchImg() {
    this.setData({
      caozuo_show: false
    })
    let row = this.data.row_data
    wx.showLoading({
      title: '处理中...',
    })
    let url = this.data.baseUrl + "/query_origin_frames";
    let data = {
      uid: row.uid,
      page: 1,
      page_size: 1,
    }

    this.post(url, data).then(res => {
      console.log("返回结果", res)
      if (res.code == 20000) {
        wx.hideLoading()
        let val = res.data.results[0]
        this.setData({
          img_src: val.frame,
          report_time: this.GMTToStr(val.report_time)

        })
        wx.showToast({
          title: res.msg,
          icon: "none"
        })
      } else {

        wx.showToast({
          title: res.msg,
          icon: "error"
        })
      }
    }).catch(err => {
      wx.hideLoading()
      // this.setData({
      //   data_list: []
      // })
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

    let self = this
    const eventChannel = this.getOpenerEventChannel()
    // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
    eventChannel.on('showOriginImg', function (data) {
      console.log(data);
      wx.setNavigationBarTitle({
        title: '查看设备原始图片'
      })
      self.setData({
        row_data: data,
        img_src: data.frame,
        origin_show: true,
        report_time: self.GMTToStr(data.report_time)
      })

    })
    eventChannel.on('showPointImg', function (data) {
      console.log(data);
      wx.setNavigationBarTitle({
        title: '查看设备关联库位状态'
      })
      if (data.status == "") {
        self.setData({
          ku_status: "满库",
          view_class: "statu_class1",
        })

      } else {
        self.setData({
          ku_status: "空库",
          view_class: "statu_class2",
        })
      }
      self.setData({
        row_data: data,
        point_show: true,
        img_src: data.points,
        report_time: data.time,
        point_index: data.index
      })

    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})